local lianji = fk.CreateSkill{
  name = "wk_heg__lianji",
}

Fk:loadTranslationTable{
  ["wk_heg__lianji"] = "连计",
  [":wk_heg__lianji"] = "当你使用非转化的普通锦囊牌指定唯一目标时，你可取消之，对其发起“军令”，若其不执行，直至本回合结束，你以此法对其发起的“军令”改为强制执行。",

  ["#wk_heg__lianji-choose"] = "连计：你可以取消 %arg 的唯一目标且对其发起“军令”",
  ["@@wk_heg__lianji_must-turn"] = "连计 强制军令",

  ["$wk_heg__lianji1"] = "两计扣用，以催强势。",
  ["$wk_heg__lianji2"] = "容老夫细细思量。",
}


local H = require "packages/ol_hegemony/util"

lianji:addEffect(fk.TargetSpecifying, {
  anim_type = "special",
  events = {},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card:isCommonTrick()
      and data.use.tos and #data.use.tos == 1 and (not data.card:isVirtual() or #data.card.subcards == 0)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local targets = data.use.tos
    local tos = #targets == 1 and targets or room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#wk_heg__lianji-choose:::" .. data.card:toLogString(),
      skill_name = lianji.name,
      cancelable = false,
    })
    local to = tos[1]
    data:cancelTarget(to)
    if to:getMark("@@wk_heg__lianji_must-turn") ~= 0 then
      H.askCommandTo(player, to, lianji.name, true)
    else
      if not H.askCommandTo(player, to, lianji.name) then
        room:setPlayerMark(to, "@@wk_heg__lianji_must-turn", 1)
      end
    end
  end,
})

return lianji
